package com.example.leetcode.array;


import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

class SolutionLCP73 {
    public int adventureCamp(String[] expeditions) {
        String[] split = expeditions[0].split("->");
        Set<String> set = new HashSet<>(Arrays.asList(split));
        int index = -1;
        int max = 0;
        for (int i = 1; i < expeditions.length; i++) {
            int count = 0;
            String expedition = expeditions[i];
            if (expedition.length() == 0) {
                continue;
            }
            String[] places = expedition.split("->");
            for (String place : places) {
                if (set.add(place)) {
                    count++;
                }
            }
            if (count > max) {
                max = count;
                index = i;
            }
        }
        return index;
    }
}


public class LCP73 {
    public static void main(String[] args) {
        SolutionLCP73 solutionLCP73 = new SolutionLCP73();
        String[] expeditions = {"leet->code", "leet->code->Campsite->Leet", "leet->code->leet->courier"};
        String[] expeditions1 = {"Alice->Dex", "", "Dex"};
        String[] expeditions2 = {"", "Gryffindor->Slytherin->Gryffindor", "Hogwarts->Hufflepuff->Ravenclaw"};
        System.out.println(solutionLCP73.adventureCamp(expeditions));
        System.out.println(solutionLCP73.adventureCamp(expeditions1));
        System.out.println(solutionLCP73.adventureCamp(expeditions2));
    }
}
